from flask import Blueprint, jsonify
from models import Website, Category, Suggestion
from flask_jwt_extended import jwt_required
from utils.response import success_response, error_response

api = Blueprint('dashboard_api', __name__)


@api.route('/', methods=['GET'])
@jwt_required()
def dashboard_data():
    try:
        site_count = Website.query.count()
        cat_count = Category.query.count()
        sug_count = Suggestion.query.count()

        data = {
            'website_count': site_count,
            'category_count': cat_count,
            'suggestion_count': sug_count
        }

        return jsonify(success_response(data))

    except Exception as e:
        return jsonify(error_response(f'获取仪表盘数据失败: {str(e)}')), 500
